//
//  InvoiceClaimNewVCController.m
//  NtoccShipper
//
//  Created by 张天兴 on 2023/6/6.
//  Copyright © 2023 zhuchongjin. All rights reserved.
//

#import "InvoiceClaimNewVCController.h"
#import "InvoiceClaimListModel.h"
#import "InvoiceClaimListCell.h"
@interface InvoiceClaimNewVCController ()<UITableViewDelegate,UITableViewDataSource>
@end

@implementation InvoiceClaimNewVCController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setTitleName:CJLString(@"已选择的发票索取")];
    [self setBackLeftButton:@""];
    [self setRightImage:CJLString(@"确定修改") image:@""];
    [self.massageButton setTitleColor:[UIColor cjMainColor] forState:(UIControlStateNormal)];
    [self.view addSubview:self.tableView];
}

- (CJTableView *)tableView{
    
    if (!_tableView) {
        _tableView = CJTableView.tbInitFrameStyle(CGRectMake(0, kTopHeight + 10,SCREEN_WIDTH,SCREEN_HEIGHT),UITableViewStylePlain)
            .tbDelegate(self)
            .tbDataSource(self)
            .tbSetOther(YES)
            .tbEstimatedRowHeight(YES)
            .tbMjHeadFooter(YES)
        ;
        _tableView.mj_header.hidden = YES;
        _tableView.mj_footer.hidden = YES;
    }
    
    return _tableView;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.modelArray.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *identifier = @"InvoiceClaimListCell";
    InvoiceClaimListCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[InvoiceClaimListCell alloc] initWithFlex:@"InvoiceClaimListCell" reuseIdentifier:identifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    InvoiceClaimListModel *model = self.modelArray[indexPath.row];
    [cell setCellInfoModel:model];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [self selectRowAtIndexPath:indexPath];
}
#pragma mark ----------数据处理

- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    InvoiceClaimListModel *model = self.modelArray[indexPath.row];
    if (model.selected) {
        model.selected = NO;
    }else{
        model.selected = YES;
    }
    [self.tableView reloadRowAtIndexPath:indexPath withRowAnimation:UITableViewRowAnimationFade];
}
- (void)backClick:(UIButton *)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)RightTextClick:(UIButton *)sender{
    NSMutableArray *arr =[[NSMutableArray array] mutableCopy];
    for (int i = 0; i < self.modelArray.count; i++) {
        InvoiceClaimListModel *cenModel = self.modelArray[i];
        if(cenModel.selected == YES){
            [arr addObject:cenModel];
        }
        
    }
    self.invoBlock(arr);
    [self.navigationController popViewControllerAnimated:YES];
}
@end
